// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import 'element-ui/lib/theme-chalk/index.css'
// import './src/styles/index.scss'
import '@/styles/index.scss'
import store from '@/store/store.js'
import ElenmentUI from 'element-ui'

// 使用Vue
Vue.use(ElenmentUI)
Vue.config.productionTip = false

// 添加路由全局守卫
router.beforeEach((to, from, next) => {
// 1 获取令牌:token
  var token = localStorage.getItem('mytoken')
  if (token) {
    next()
  } else {
    // 如果是访问默认可以访问的页面,如登录,那么也不需要有令牌
    if (to.path === '/login') {
      next()
    } else {
      next({path: '/login'})
    }
  }
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store: store,
  components: { App },
  template: '<App/>'
})
